import 'package:leader_doctor_flutter/common/data/app.dart';
import 'package:leader_doctor_flutter/plugins/plugins_messages.g.dart';
import 'package:logger/logger.dart';
import 'dart:developer' as log;

var logger = Logger(
  output: ConsoleLogWrite(),
  printer: PrettyPrinter(),
);

class ConsoleLogWrite extends LogOutput {
  @override
  void output(OutputEvent event) {
    for (var str in event.lines) {
      if (App.hasPigeons) {
        NativeInterface().log(str);
      } else {
        log.log(str);
      }
    }
  }
}

class Log {
  static d(
    dynamic message, {
    DateTime? time,
    Object? error,
    StackTrace? stackTrace,
  }) {
    logger.d(message, time: time, error: error, stackTrace: stackTrace);
  }

  static i(
    dynamic message, {
    DateTime? time,
    Object? error,
    StackTrace? stackTrace,
  }) {
    logger.i(message, time: time, error: error, stackTrace: stackTrace);
  }

  static w(
    dynamic message, {
    DateTime? time,
    Object? error,
    StackTrace? stackTrace,
  }) {
    logger.w(message, time: time, error: error, stackTrace: stackTrace);
  }

  static e(
    dynamic message, {
    DateTime? time,
    Object? error,
    StackTrace? stackTrace,
  }) {
    logger.e(message, time: time, error: error, stackTrace: stackTrace);
  }

  static f(
    dynamic message, {
    DateTime? time,
    Object? error,
    StackTrace? stackTrace,
  }) {
    logger.f(message, time: time, error: error, stackTrace: stackTrace);
  }
}
